// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   stock_apply_ok.java

package qcs.qcs;

import com.jspsmart.upload.SmartUpload;
import include.nseer_cookie.counter;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class stock_apply_ok extends HttpServlet
{

	public stock_apply_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			counter count = new counter(dbApplication);
			SmartUpload mySmartUpload = new SmartUpload();
			mySmartUpload.setCharset("UTF-8");
			nseer_db_backup1 qcs_db = new nseer_db_backup1(dbApplication);
			nseer_db_backup1 qcs_db1 = new nseer_db_backup1(dbApplication);
			if (qcs_db.conn((String)dbSession.getAttribute("unit_db_name")) & qcs_db1.conn((String)dbSession.getAttribute("unit_db_name")))
				try
				{
					String product_id = request.getParameter("product_id");
					String sql6 = (new StringBuilder("select amount from stock_balance_details where product_id='")).append(product_id).append("' and qcs_apply_tag='0' order by stock_ID").toString();
					String sqla;
					for (ResultSet rs6 = qcs_db1.executeQuery(sql6); rs6.next(); qcs_db.executeUpdate(sqla))
					{
						Double qualified_amount = Double.valueOf(rs6.getDouble("amount") - rs6.getDouble("unqualified_amount"));
						sqla = (new StringBuilder("update stock_balance_details set qualified_amount='")).append(qualified_amount).append("' where product_id='").append(product_id).append("' and qcs_apply_tag='0'").toString();
					}

					qcs_db.commit();
					qcs_db.close();
				}
				catch (Exception ex)
				{
					response.sendRedirect("qcs/qcs/stock_register_ok.jsp?finished_tag=1");
				}
			else
				response.sendRedirect("error_conn.htm");
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
